package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFillInsert;
import com.sky.annotation.AutoFillUpdate;
import com.sky.entity.Employee;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);

    /**
     * 按用户名选择计数
     *
     * @param username 用户名
     * @return {@link Integer}
     */
    @Select("select count(*) from employee where username = #{username}")
    Integer selectCountByUsername(String username);

    /**
     * 新增员工
     *
     * @param employee
     */
    @AutoFillInsert
    void insert(Employee employee);

    /**
     * 选择页面
     *
     * @param employeeQuery 员工查询
     * @return {@link Page}<{@link Employee}>
     */
    Page<Employee> selectPage(Employee employeeQuery);

    /**
     * 按id更新状态
     *
     * @param id     id
     * @param status 地位
     */
    @AutoFillUpdate
    void updateStatusById(Long id, Integer status);

    /**
     * 按id更新
     *
     * @param employee 受雇者
     */
    @AutoFillUpdate
    void updateById(Employee employee);

    /**
     * 按id选择
     *
     * @param id id
     * @return {@link Employee}
     */
    @Select("select id, name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user from employee where id = #{id}")
    Employee selectById(Long id);

    /**
     * 按用户名而非id选择计数
     *
     * @param username 用户名
     * @param id       id
     * @return {@link Integer}
     */
    Integer selectCountByUsernameAndNotId(String username, Long id);
}
